<template>
  <div>
    <ComDialog
      @EventClose="closeFn"
      :title="isEdit ? '修改' : '新增'"
      @
      :dialogVisible="dialogVisible"
    >
      <el-form
        ref="comForm"
        label-width="100px"
        :model="dataForm"
        :rules="FormRules"
      >
        <el-form-item prop="keyword" label="关键词">
          <el-input v-model="dataForm.keyword"></el-input>
        </el-form-item>
        <el-form-item v-show="!isEdit" prop="synonym" label="近似词">
          <el-input v-model="dataForm.synonym"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="closeFn">取消</el-button>
          <el-button type="primary" @click="saveFn">保存</el-button>
        </el-form-item>
      </el-form>
    </ComDialog>
  </div>
</template>

<script>
import ComDialog from "../../../components/comDialog.vue";
import { getSynonymeGetInfoAPi } from "@/wss/api/ContentSupervision/similar.js";
export default {
  components: { ComDialog },
  props: {
    isEdit: {
      type: Boolean,
      default: false,
    },
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      dataForm: {
        keyword: "",
        synonym: "",
      },
      FormRules: {
        keyword: [
          { type: "string", message: "无效", required: true, trigger: "blur" },
        ],
        synonym: [
          { type: "string", message: "无效", required: true, trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    //   根据 获取详细
    async getDetailFn(row) {
      let { data, code } = await getSynonymeGetInfoAPi({ id: row.idStr });
      if (code == 200) {
        this.dataForm = data;
      }
    },
    //   关闭函数
    closeFn() {
      this.$emit("update:dialogVisible", false);
      this.$refs.comForm.resetFields();
      //   后期再改不用延时器
      this.dataForm = {
        keyword: "",
        synonym: "",
      };
      setTimeout(() => {
        this.$emit("EventisEdit");
      }, 300);
    },
    // 保存
    saveFn() {
      if (this.dataForm.idStr) {
        this.dataForm.id = this.dataForm.idStr;
      }
      this.$emit("EventgetData", this.dataForm);
    },
  },
};
</script>

<style>
</style>